#ifndef _DSWUPGRADE_H
#define _DSWUPGRADE_H
#include <libbase/dswbase.h>

class CDswupgrade : public CDswbase
{
public:
	CDswupgrade(LPST_ENV_T pEnv);
	virtual ~CDswupgrade();
private:
	int GetPartitionSize(char* pPartionName);
	void StartDownLoad(LPST_UPGRADE_T pUpgrade);
	void StartUpgrade(LPST_FIRMWARE_T pFirmware);

	bool CheckUpgradeFile(LPST_UPGRADE_T pUpgrade);

	static void* cbUpgradeThreadFunc(void* pParam){((CDswupgrade*)pParam)->UpgradeThreadFunc();return NULL;};
	void UpgradeThreadFunc();
	bool FlashEraseBlock(int ndev, unsigned long nblockaddr, unsigned long nerasesize);
	bool UpgradePartion(LPST_UPGRADE_T pUpgrade);
	void UpdateAppInfo(LPST_UPGRADE_T pUpgrade);

	bool HttpDownloadFile(char* pURL);
	
	static size_t cbHttpGetContentLengthFunc(void *contents, size_t size, size_t nmemb, void *userp){return ((CDswupgrade*)userp)->HttpGetContentLengthFunc(contents, size, nmemb);};
	size_t HttpGetContentLengthFunc(void *contents, size_t size, size_t nmemb);
	static size_t cbHttpRecvDataFunc(void *contents, size_t size, size_t nmemb, void *userp){return ((CDswupgrade*)userp)->HttpRecvDataFunc(contents, size, nmemb);};
	size_t HttpRecvDataFunc(void *contents, size_t size, size_t nmemb);
protected:
	virtual int OnMessage(EN_MSG_TYPE nMsgType, void * pParam);
private:
	pthread_t m_nUpgradeThread_id;
	ST_UPGRADE_T m_nUpgrade;
	bool m_bExitThread;
	FILE* m_pFile;
	int m_nFileLen;
};

#endif

